package com.apes.fa.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.jpa.tuple.date.DateTime;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.account.account.model.Cooperation;
import com.apes.scm.account.tax.model.Tax;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.Classify;
import com.apes.scm.masterdata.product.model.Product;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenerationTime;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @description: 进销存分析
 * @author: muting
 * @create: 2022-12-05 17:11
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = FaPurchaseSaleStorage.CONST_TABLE_NAME)
public class FaPurchaseSaleStorage extends Model {

    public final static  String CONST_TABLE_NAME = "fa_purchase_sale_storage";

    @Id
    @Column(name = "id", nullable = false, length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "库存结余编号", prefix = "ZJ", padding = 5)
    @Comment("库存结余编号")
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    @Comment("公司")
    private PartyRole company;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment("商品")
    private Product product;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "classify_id", referencedColumnName = "id")
    @Comment("品类")
    private Classify classifyId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "cooperation_id", referencedColumnName = "id")
    @Comment("合作方式")
    private Cooperation cooperation; //合作方式

    @Column(name = "beginning_quantity")
    @Comment("期初数量")
    private Integer beginningQuantity;

    @Column(name = "beginning_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("期初金额")
    private double beginningAmount = 0;

    @Column(name = "current_quantity")
    @Comment("本期入库数量")
    private Integer currentQuantity;

    @Column(name = "current_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("本期入库金额")
    private double currentAmount = 0;

    @Column(name = "return_quantity")
    @Comment("本期返厂数量")
    private Integer returnQuantity;

    @Column(name = "return_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("本期返厂金额")
    private double returnAmount = 0;

    @Column(name = "transfer_quantity")
    @Comment("本期调拨数量")
    private Integer transferQuantity;

    @Column(name = "transfer_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("本期调拨金额")
    private double transferAmount = 0;

    @Column(name = "sales_quantity")
    @Comment("本期销售数量")
    private Integer salesQuantity;

    @Column(name = "sales_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("本期销售金额")
    private double salesAmount = 0;

    @Column(name = "change_quantity")
    @Comment("本期变价数量")
    private Integer changeQuantity;

    @Column(name = "change_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("本期变价金额")
    private double changeAmount = 0;

    @Column(name = "end_quantity")
    @Comment("期末库存数量")
    private Integer endQuantity;

    @Column(name = "end_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("期末库存金额")
    private double endAmount = 0;


    @Column(name = "error_checking", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("验错")
    private Integer errorChecking = 0;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @DateTime(GenerationTime.INSERT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "time", updatable = false)
    @Comment("日期")
    private Date time;

}
